import {
  Controller,
  Get,
  Post,
  Query,
  Request,
  Headers,
  Param,
  Body
} from '@nestjs/common'
import { GirlService } from './girl.service'
import { ApiTags } from '@nestjs/swagger'

@ApiTags('练习')
@Controller('girl')
export class GirlController {
  constructor(private girService: GirlService) {}

  @Get()
  getGirl(): any {
    return this.girService.getGirls()
  }

  // @Get('getGirlById')
  // getGirlById(@Request() req): any {
  //   const id: number = parseInt(req.query.id);

  //   return this.girService.getGirlById(id);
  // }

  // 采用 @Query装饰器来解析 query参数
  @Get('getGirlById')
  getGirlById(@Query() query): any {
    const id: number = parseInt(query.id)

    return this.girService.getGirlById(id)
  }

  // 增加post方法
  @Post('add')
  addGirl(@Request() req) {
    return this.girService.addGirl(req)
  }

  @Get('delete/:id')
  deleteGirl(@Param() params) {
    return this.girService.deleteGirl(params)
  }

  // 动态路由
  @Get('findGirlById/:id')
  findGirlById(@Request() req) {
    console.log(req.params)

    const id = parseInt(req.params.id)

    console.log(id)
    return this.girService.getGirlById(id)
  }

  // 多个动态参数
  @Get('findGirlBy/:id/:name')
  findGirlBy(@Request() req, @Headers() headers) {
    console.log(req.params)
    console.log(headers)

    const id = parseInt(req.params.id)

    console.log(id)
    return this.girService.getGirlById(id)
  }

  @Post('updateGirl')
  updateGirl(@Body() req) {
    return this.girService.updateGirl(req)
  }

  @Get('getAllPerson')
  getAllPerson() {
    return this.girService.getAllPerson()
  }

  @Post('getPerson')
  getPerson(@Body() req) {
    return this.girService.getPerson(req)
  }
}
